package demo18;

import java.util.ArrayList;
import java.util.List;

/**
 * 组合
 * https://leetcode.cn/problems/uUsW3B/
 */
class Solution {
    List<List<Integer>> ret = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    int k; // 长度
    public List<List<Integer>> combine(int n, int k) {
        this.k = k;
        dfs(n,1);
        return ret;
    }

    private void dfs(int n, int pow) {
        if(path.size() == k) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for(int i = pow; i <= n; i++) {
            path.add(i);
            dfs(n,i+1);
            path.remove(path.size() - 1);
        }
    }
}